define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var mqtt = require("../mqttclient/mqtt-baidu");
	require("../lib/moment.min");

	var comm = require('../lib/user/comm');

	var Model = function(){
		this.callParent();
		this.timerTime = null;
	};

	Model.prototype.doMsgArrivedStatus = function (message) {
		//justep.Util.hint('status data arrived');

		var buff = message.payloadBytes;
		var vb = new Uint8Array(buff);
		var dataV = new Int8Array(buff);

		var year = vb[0] + vb[1]*256;
		var time = moment([year, vb[2]-1, vb[3], vb[4], vb[5], vb[6], 0]); // 初始化是月从0开始；0=1月
		var timestr = moment(time).format('MM-DD HH:mm');

		var runtime = (vb[7] + vb[8]*256 + vb[9]*256*256 + vb[10]*256*256*256) / 3600;
		var volt = vb[11] + vb[12]*256;
		var gprs = dataV[13];

	    this.getElementByXid('txtXHQD').innerHTML = -gprs + 'dB';
	    this.getElementByXid('txtDCDL').innerHTML = volt + 'mV';
	    this.getElementByXid('txtSJZQ').innerHTML = runtime.toFixed(1) + '小时';
	    this.getElementByXid('txtZHSB').innerHTML = timestr;

    };

	Model.prototype.modDevStatusLoad = function(event){
        var self = this;
//		this.timerTime = setInterval(function () {
//			var timestr = moment().format(comm.gParams.timeFormat.std);
//		    self.getElementByXid('txtTime').innerHTML = timestr;
//		}, 1000);

        var self = this;
		mqtt.onMsgArrivedStatus = function(message) { self.doMsgArrivedStatus(message);};
	};

	Model.prototype.modDevStatusUnLoad = function(event){
		//clearInterval(this.timerTime);
		mqtt.unsubscribe(comm.gParams.baiduTopics.status + '/#');
	};


	return Model;
});